#ifndef __RSA_HPP__
#define __RSA_HPP__

#include "Integer.hpp"
#include "Algorithm.hpp"
#include "GenericException.hpp"

class RSA : public Algorithm {
	private:
		Integer n, e, d; /**< RSA variables */
		bool isSetup; /**< set to true, if keypair has been set up */
	public:
		RSA();
		
		// see lecture slides for explanation of variables
		const Integer& getN() const;
		const Integer& getE() const;
		const Integer& getD() const;
		
		/**
		 * generates a new keypair and stores result in private variables n, e, d
		 * @param bits number of bits used for key generation
		 */
		void setup(unsigned int bits);
		
		/**
		 * encrypts given plaintext
		 */
		Block encrypt(const Block &plaintext) const;
		
		/**
		 * decrypts given plaintext
		 */
		Block decrypt(const Block &ciphertext) const;
		
		/**
		 * dumps internal variables to stderr
		 */
		void dump();
		
		/**
		 * writes RSA parameters to given file
		 * @param filename
		 */
		void writeParametersToFile(const std::string &Filename) const;
		
		/**
		 * reads RSA parameters from given file
		 * @param filename
		 */
		void readParametersFromFile(const std::string &filename);
		
		/**
		 * @returns block size in bytes
		 */
		unsigned int getBlockSize() const;
};
#endif
